package com.ml.mall.mapper.sys;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.req.sys.SysUserRoleQueryDto;
import com.ml.mall.bean.vo.sys.SysUserRoleVO;
import com.ml.mall.entity.sys.SysRoleUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    * 用户角色表 Mapper 接口
    * </p>
*
* @author kyyang
* Created 2021-01-06
*/
    @Mapper
    @Repository
    public interface SysRoleUserMapper extends BaseMapper<SysRoleUser> {

    @Select("select * from sys_role_user where userId=#{userId}")
    List<SysRoleUser> selectByUserId(@Param("userId") long id);

    int deleteByRoleIds(@Param("roleIds") List<Integer> roleIds);

    @Delete("delete from sys_role_user where roleId = #{roleId} and userId = #{userId}")
    int deleteByKey(@Param("userId") Long userId, @Param("roleId") Integer id);

    List<SysUserRoleVO> selectUserRole(@Param("dto") SysUserRoleQueryDto sysUserRoleQueryDto);
    @Select("select * from sys_role_user where userId=#{userId} and roleId = #{roleId}")
    SysRoleUser selectByKey(@Param("roleId") Integer id, @Param("userId") Long userId);
}
